home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / GLX / littleRedCap / x_interfere.c < prev   
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.9 KB  |  202 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <sys/types.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <math.h>
  21.  
  22. #include <X11/Intrinsic.h>
  23. #include <X11/StringDefs.h>
  24. #include <Xm/Frame.h>
  25. #include <Xm/PushB.h>
  26.  
  27. #include "main.h"
  28. #include "interfere.h"
  29.  
  30. /*
  31.  * For naming the widgets' resources.
  32.  */
  33. #define APP_NAME "interfere"
  34. #define APP_CLASS "Interfere"
  35.  
  36. /*
  37.  * In case there's no app-defaults file.
  38.  */
  39. static String fallbacks[] =
  40. {
  41.     "*canvasFrame.width: 500",
  42.     "*canvasFrame.height: 400",
  43.     "*canvasFrame.leftOffset: 20",
  44.     "*canvasFrame.topOffset: 40",
  45.     "*canvasFrame.rightOffset: 120",
  46.     "*canvasFrame.bottomOffset: 40",
  47.     "*Quit.rightOffset: 10",
  48.     "*Quit.bottomOffset: 10",
  49.     "*Animate.rightOffset: 10",
  50.     "*Animate.bottomOffset: 50",
  51.     NULL,
  52. };
  53.  
  54. /*
  55.  * Called from main() when the toplevel widget is created.
  56.  */
  57. char * 
  58. getAppName (void)
  59. {
  60.     return APP_NAME;
  61. }
  62.  
  63. /*
  64.  * Called from main() when the toplevel widget is created.
  65.  */
  66. char * 
  67. getAppClass (void)
  68. {
  69.     return APP_CLASS;
  70. }
  71.  
  72. /*
  73.  * So that the XtOpenDisplay can set them in main().
  74.  */
  75. void 
  76. setFallbackResources(XtAppContext app_context)
  77. {
  78.     XtAppSetFallbackResources(app_context, fallbacks);
  79. }
  80.  
  81. /*
  82.  * This is called until we press the 'Stop' button.
  83.  */
  84. static Boolean 
  85. animateWorkProc (XtPointer client_data)
  86. {
  87.     drawScene ();
  88.     return False; 
  89. }
  90.  
  91. /*
  92.  * If there are any application-specific resources, specify them here.
  93.  */
  94. XrmOptionDescRec * 
  95. getResourceDescriptions (int * num_desc)
  96. {
  97.     *num_desc = 0;
  98.     return NULL;
  99. }
  100.  
  101. /*
  102.  * Using the framing widget's dimensions, request a gl drawing area.
  103.  */
  104. Widget 
  105. setupGLWidget (Widget parent)
  106. {
  107.     Arg args[2];
  108.     unsigned int n = 0;
  109.     unsigned int width = 0, height = 0;
  110.     Widget canvas = NULL;
  111.  
  112.     XtVaGetValues(parent, 
  113.                   XmNwidth, &width,
  114.                   XmNheight, &height,
  115.                   NULL);
  116.     canvas =  initGLWidget(parent, width, height);
  117.     return canvas;
  118. }
  119.  
  120. /*
  121.  * Used when the Animate/Stop button is pressed.
  122.  */
  123. static void 
  124. animateCallback (Widget w, XtPointer client, XtPointer callback)
  125. {
  126.     static Boolean toggle = False;
  127.     static work_proc_id = 0;
  128.     XmString string;
  129.     XtAppContext app_context = (XtAppContext)client;
  130.  
  131.     if (!toggle) {
  132.         Boolean animateWorkProc(XtPointer);
  133.         work_proc_id = XtAppAddWorkProc(app_context, animateWorkProc, NULL);
  134.         string = XmStringCreateSimple("Stop");
  135.         toggle = True;
  136.     }
  137.     else {
  138.         XtRemoveWorkProc(work_proc_id);
  139.         string = XmStringCreateSimple("Animate");
  140.         toggle = False;
  141.     }
  142.  
  143.     XtVaSetValues(w, XmNlabelString, string, NULL);
  144.     XmStringFree(string);
  145. }
  146.  
  147. /*
  148.  *
  149.  */
  150. static void 
  151. quitCallback (Widget w, XtPointer client, XtPointer callback)
  152. {
  153.     exit(0);
  154. }
  155.  
  156. /*
  157.  * Set up the application's desktop.
  158.  */
  159. Widget 
  160. setupDesktop (Widget parent, XtAppContext app_context)
  161. {
  162.     Widget quit_button = XtVaCreateManagedWidget
  163.                           ("Quit", xmPushButtonWidgetClass, parent,
  164.                            XmNrightAttachment, XmATTACH_FORM,
  165.                            XmNbottomAttachment, XmATTACH_FORM,
  166.                            XmNtraversalOn, False,
  167.                            NULL);
  168.     Widget animate_button = XtVaCreateManagedWidget
  169.                              ("Animate", xmPushButtonWidgetClass, parent,
  170.                               XmNrightAttachment, XmATTACH_FORM,
  171.                               XmNbottomAttachment, XmATTACH_FORM,
  172.                               XmNtraversalOn, False,
  173.                               NULL);
  174.  
  175.     Widget frame = XtVaCreateWidget("canvasFrame", xmFrameWidgetClass,
  176.                                     parent,
  177.                                     XmNbottomAttachment, XmATTACH_FORM,
  178.                                     XmNtopAttachment, XmATTACH_FORM,
  179.                                     XmNleftAttachment, XmATTACH_FORM,
  180.                                     XmNrightAttachment, XmATTACH_FORM,
  181.                                     NULL);
  182.  
  183.  
  184.     XtAddCallback(animate_button, XmNactivateCallback, animateCallback, 
  185.                   app_context);
  186.     XtAddCallback(quit_button, XmNactivateCallback, quitCallback, NULL);
  187.     return frame;
  188. }
  189.  
  190. /*
  191.  * Manage the framing widget.  Creating and managing became a two 
  192.  * step process to decouple the GL drawing area creation from an
  193.  * Open GL or GL specific widget.  The glXgetConfig didn't like
  194.  * some of the parameters I'd specified for the GL implementation.
  195.  */
  196. void
  197. showGLWidget (Widget parent)
  198. {
  199.     XtManageChild(parent);
  200. }
  201.  
  202.